﻿namespace Microsoft.SharePoint.Client
{
    using System;
    using System.ComponentModel;

    [ScriptType("SP.RecycleBinItem", ServerTypeId="{5ebf462e-9e9a-440c-992b-abbb3916563d}")]
    public class RecycleBinItem : ClientObject
    {
        [EditorBrowsable(EditorBrowsableState.Never)]
        public RecycleBinItem(ClientRuntimeContext Context, ObjectPath ObjectPath) : base(Context, ObjectPath)
        {
        }

        [Remote]
        public void DeleteObject()
        {
            ClientAction query = new ClientActionInvokeMethod(this, "DeleteObject", null);
            base.Context.AddQuery(query);
            base.RemoveFromParentCollection();
        }

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);
            if (!flag)
            {
                switch (peekedName)
                {
                    case "Id":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Id"] = reader.ReadGuid();
                        return flag;

                    case "ItemState":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["ItemState"] = reader.ReadEnum<RecycleBinItemState>();
                        return flag;

                    case "ItemType":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["ItemType"] = reader.ReadEnum<RecycleBinItemType>();
                        return flag;

                    case "Title":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Title"] = reader.ReadString();
                        return flag;

                    case "DirName":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["DirName"] = reader.ReadString();
                        return flag;

                    case "LeafName":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["LeafName"] = reader.ReadString();
                        return flag;

                    case "Author":
                        flag = true;
                        reader.ReadName();
                        this.Author.FromJson(reader);
                        return flag;

                    case "DeletedBy":
                        flag = true;
                        reader.ReadName();
                        this.DeletedBy.FromJson(reader);
                        return flag;

                    case "DeletedDate":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["DeletedDate"] = reader.ReadDateTime();
                        return flag;

                    case "Size":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Size"] = reader.ReadInt64();
                        return flag;
                }
            }
            return flag;
        }

        [Remote]
        public void Restore()
        {
            ClientAction query = new ClientActionInvokeMethod(this, "Restore", null);
            base.Context.AddQuery(query);
            base.RemoveFromParentCollection();
        }

        [Remote]
        public User Author
        {
            get
            {
                object obj2;
                if (base.ObjectData.ClientObjectProperties.TryGetValue("Author", out obj2))
                {
                    return (User) obj2;
                }
                User user = new User(base.Context, new ObjectPathProperty(base.Context, base.Path, "Author"));
                base.ObjectData.ClientObjectProperties["Author"] = user;
                return user;
            }
        }

        [Remote]
        public User DeletedBy
        {
            get
            {
                object obj2;
                if (base.ObjectData.ClientObjectProperties.TryGetValue("DeletedBy", out obj2))
                {
                    return (User) obj2;
                }
                User user = new User(base.Context, new ObjectPathProperty(base.Context, base.Path, "DeletedBy"));
                base.ObjectData.ClientObjectProperties["DeletedBy"] = user;
                return user;
            }
        }

        [Remote]
        public DateTime DeletedDate
        {
            get
            {
                base.CheckUninitializedProperty("DeletedDate");
                return (DateTime) base.ObjectData.Properties["DeletedDate"];
            }
        }

        [Remote]
        public string DirName
        {
            get
            {
                base.CheckUninitializedProperty("DirName");
                return (string) base.ObjectData.Properties["DirName"];
            }
        }

        [Remote]
        public Guid Id
        {
            get
            {
                base.CheckUninitializedProperty("Id");
                return (Guid) base.ObjectData.Properties["Id"];
            }
        }

        [Remote]
        public RecycleBinItemState ItemState
        {
            get
            {
                base.CheckUninitializedProperty("ItemState");
                return (RecycleBinItemState) base.ObjectData.Properties["ItemState"];
            }
        }

        [Remote]
        public RecycleBinItemType ItemType
        {
            get
            {
                base.CheckUninitializedProperty("ItemType");
                return (RecycleBinItemType) base.ObjectData.Properties["ItemType"];
            }
        }

        [Remote]
        public string LeafName
        {
            get
            {
                base.CheckUninitializedProperty("LeafName");
                return (string) base.ObjectData.Properties["LeafName"];
            }
        }

        [Remote]
        public long Size
        {
            get
            {
                base.CheckUninitializedProperty("Size");
                return (long) base.ObjectData.Properties["Size"];
            }
        }

        [Remote]
        public string Title
        {
            get
            {
                base.CheckUninitializedProperty("Title");
                return (string) base.ObjectData.Properties["Title"];
            }
        }
    }
}

